import pygame
import data_inputer
import node_class
from node_effector import *
def TransformScreenCoord(nodes:dict):
    '''
    将坐标转换为屏幕坐标
    '''
    for node in nodes.values():
        node:node_class.Node
        node.x=int(node.x*40)+20
        node.y=int(node.y*40)+100
def draw_node(x, y):
    pygame.draw.circle(screen, (255,0,0), (x, y), 10)
def draw_line(x1,y1,x2,y2):
    pygame.draw.line(screen, (0, 0, 0), (x1, y1), (x2, y2), 5)

if __name__ == "__main__":
    pygame.init()# 初始化pygame
    size = (1600, 900)# 设置窗口大小
    screen = pygame.display.set_mode(size)
    
    pygame.display.set_caption("window")# 设置窗口名
    screen.fill((255,255,240))# 设置背景颜色
    # pygame.draw.circle(screen, (0, 255, 0), (300, 300), 100)
    # pygame.draw.line(screen, (255, 255, 255), (0, 0), (500, 500), 5)
    font = pygame.font.Font("font/DENGB.TTF",20)# 设置字体
    text = font.render('hello pygame', True, (0, 255, 0))
    screen.blit(text, (100, 100))
    #TransformScreenCoord(data_inputer.NODES)
    for node in data_inputer.NODES.values():#画路径
        for neighbor in node.neighbors.keys():
            draw_line(node.x,node.y,data_inputer.NODES[neighbor].x,data_inputer.NODES[neighbor].y)
    
    for node in data_inputer.NODES.values():#画节点
        var=NodeEffector(node)
        # draw_node(node.x,node.y)
        text = font.render(f'{node.id}', True, (0, 255, 0))
        screen.blit(text, (node.x-10, node.y-10))
    print(len(NodeEffector.Static_Dict))
    for ne in NodeEffector.Static_Dict.values():
        ne:NodeEffector
        ne.DrawCircles(screen)
    pygame.display.flip()#刷新窗口



    # 等待用户关闭窗口
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

    pygame.quit()